//    Copyright (C) Kherty.  All rights reserved.
namespace OpenLS.Spreadsheet
{
    public class NotContainsBlanksFormattingRule : StandardConditionalFormattingRule
    {
        internal override ConditionalFormattingType Type
        {
            get { return ConditionalFormattingType.NotContainsBlanks; }
        }
        internal override bool Apply(Cell cell)
        {
            object s = cell.Value;
            bool applies = s != null && (!(s is string) || !string.IsNullOrEmpty((string) s));
            return ApplyStyle(cell, applies);
        }
        internal override void PrepareBeforeWrite(ConditionalFormatting conditionalFormatting, FormatType formatType)
        {
            var cell = conditionalFormatting.Range.TopLeftCell;
            Formula1 = string.Format("=LEN(TRIM({0}))>0", cell.Label);
        }
    }
}
